from sqlalchemy import create_engine, Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker

Base = declarative_base()


class User(Base):
    __tablename__ = 'users'
    id = Column(Integer, primary_key=True)
    name = Column(String(50))

    def __repr__(self):
        return "<User(name='%s')>" % self.name


engine = create_engine("mysql+pymysql://sqlalchemy:sqlalchemy@127.0.0.1:33060/sqlalchemy", max_overflow=5)
# Base.metadata.create_all(engine)

Session = sessionmaker()
Session.configure(bind=engine)
session = Session()

# ad_user = User(name='张三')
#
# session.add(ad_user)
#
# session.commit()

list_user = session.query(User).filter_by(name='张三')

print(list_user)
